4 ...\PTVR_Researchers\Python_Scripts\Experiments\visual_search.py
8 When using a pointer, it is necessary to specify your headset's manufacturer:
9 headset_manufacturer = "Vive" (default) refers to the HTC Vive pro series headsets.
10 headset_manufacturer = "Oculus" refers to the Quest 1, 2 or 3 headsets (in keeping
11 with OpenXR terminology).
13 my_world = The3DWorld (
14 headset_manufacturer = "Vive" # "Vive" by default
24 from PTVR.Data.Callback import AddInteractionPassedToCallback, EndCurrentScene,ChangeObjectOutline,ChangeAudioSettings
26 from numpy
import array
36 viewpoint_position = array ([0, height_of_head, 0])
42 number_of_distractor = 512
44 radial_distance_min_max_values = array([2, 15])
53 hand = LaserContingency.RIGHT_HAND
61 headset_manufacturer =
"Vive"
69 sound_end_of_block =
"applaudisement.mp3"
70 sound_wrong_response =
"buzzer.ogg"
71 handcontroller_id = my_world.handControllerRight.id
72 configurations_set = set()
75 if(random_value == 1):
76 value = random.randint (0, 1)
78 color_object = color_base
80 color_object = color_distractor
82 my_object =
Sphere(size_in_meters= array([0.2, 0.2, 0.2]), color = color_object)
84 my_object =
Cube(size_in_meters= array([0.2, 0.2, 0.2]), color = color_base)
88 reticle_pointing_at_object = PointedAt (target_id = my_object.id,
89 activation_cone_origin_id=handcontroller_id,
90 activation_cone_radius_deg=1, activation_cone_depth=500, mode=
"press",
91 event_name=
"object_is_pointed_at")
92 reticle_NOT_pointing_at_object = PointedAt (target_id = my_object.id,
93 activation_cone_origin_id=handcontroller_id,
94 activation_cone_radius_deg=1, activation_cone_depth=500, mode=
"release",
95 event_name=
"object_is_not_pointed_at")
96 return reticle_pointing_at_object, reticle_NOT_pointing_at_object
103 return callback_outline_on,callback_outline_off
106 print(
"Creating an experiment to study visual search in various 3D regions...")
108 my_initial_scene = CheckScene ( my_world = my_world,
109 are_both_hand_controllers_visible=
True,
110 text_information =
"In this experiment you have "\
111 "to search for the red cube \n among over objects " \
112 "by pointing at it and pressing the trigger.\n" \
113 "When you are ready to start, please press the trigger.")
114 my_world.add_scene (my_initial_scene)
117 my_scene = VisualScene (is_right_hand_controller_visible =
True)
120 my_laser_beam = PointingLaser ( hand_laser = hand,
121 laser_color = my_laser_color,
123 my_scene.place_pointing_laser ( my_laser_beam )
124 my_scene.AddPointingCursor(my_laser_beam)
127 my_world.translate_coordinate_system_along_current(translation = viewpoint_position)
129 audio_wrong =
AudioSource(audio_file=sound_wrong_response, is_playing_directly=
False)
130 my_scene.place(audio_wrong,my_world)
131 while len(configurations_set) < number_of_distractor+1:
133 radialdistance = random.uniform(radial_distance_min_max_values [0],
134 radial_distance_min_max_values [1])
135 eccentricity = random.gauss(90, 40)
136 halfmeridian = random.randint(0, 360)
137 configuration = (radialdistance, eccentricity, halfmeridian)
138 if tuple(configuration)
not in configurations_set:
139 configurations_set.add(tuple(configuration))
141 configurations = [list(config)
for config
in configurations_set]
142 target_configuration = random.choice(configurations)
143 print(
"my target is at np.array([radial_distance,eccentricity,half_meridian)) : " +
144 str(target_configuration))
145 for config
in configurations:
146 radialdistance = config[0]
147 eccentricity = config[1]
148 halfmeridian = config[2]
149 if(config != target_configuration):
152 my_object =
Cube(size_in_meters= array([0.2, 0.2, 0.2]), color=color_target)
153 my_object.set_perimetric_coordinates(radialDistance=radialdistance,
154 eccentricity=eccentricity, halfMeridian=halfmeridian)
155 my_scene.place(my_object, my_world)
156 inside,outside = create_events_when_pointing_at_objects (my_object)
159 press =
HandController(valid_responses=[
'right_trigger'],mode=
"press",event_name=
"press")
160 if(config != target_configuration):
165 my_scene.AddInteraction(events=[inside], callbacks=[add,outline_on])
166 my_scene.AddInteraction(events=[outside], callbacks=[remove,outline_off])
174 my_scene.AddInteraction(events=[inside], callbacks=[add,outline_on])
175 my_scene.AddInteraction(events=[outside], callbacks=[remove,outline_off])
178 my_world.add_scene(my_scene)
180 my_world.reset_coordinate_system()
182 calibration =
CheckScene(my_world = my_world,text_information=
"Congratulations!",are_both_hand_controllers_visible =
True)
184 calibration.place(audio,my_world)
185 my_world.add_scene(calibration)
188 print(
"The .json file corresponding to this experiment has been created.")
191 if __name__ ==
"__main__":
def LaunchThe3DWorld(jsonFileCategory="Externals")
def new_objects(random_value)
def create_events_when_pointing_at_objects(my_object)
def create_callbacks_to_change_objects(my_object)